package com.threeSales.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.threeSales.entity.Admin;
import com.threeSales.entity.UserNexus;

@Repository
public class UserNexusDao {
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public int aotuAdd(UserNexus userNexus){
		String sql = "insert into tb_user_nexus (fid,lowerid,level) values(?,?,?)";
		Object[] params = {userNexus.getFid(),userNexus.getLowerid(),userNexus.getLevel()};
		return jdbcTemplate.update(sql, params);
	}
	
	public int nexusAdd(UserNexus userNexus){
		String sql = "insert into tb_user_nexus (fid,lowerid,level) values(?,?,?)";
		Object[] params = {userNexus.getFid(),userNexus.getLowerid(),userNexus.getLevel()};
		return jdbcTemplate.update(sql, params);
	}
	
	public List<UserNexus> findByfid(String fid){
		String sql = "SELECT * FROM tb_tb_user_nexus WHERE fid=?";
		List<UserNexus> userNexusList = new ArrayList();
		List list = new ArrayList();
		 list = jdbcTemplate.queryForList(sql,new Object[] {fid});
		 Iterator it = list.iterator();
		 HashMap hashMap = new HashMap();
		 while(it.hasNext()){
			 hashMap = (HashMap) it.next();
			 UserNexus userNexus = new UserNexus();
			 userNexus.setId((int)hashMap.get("id"));
			 userNexus.setFid((String)hashMap.get("fid"));
			 userNexus.setLowerid((String)hashMap.get("lowerid"));
			 userNexus.setLevel((String)hashMap.get("level"));
			 userNexusList.add(userNexus);
		 }
		 return userNexusList;
	}
}
